<?php

session_start();
if(!array_key_exists("user", $_SESSION) || $_SESSION['account'] != 2){
	header("Location: ../common/redirect.php");
	exit;
}

include_once("../class/db.php");
$db = new db();

$sql = "SELECT * FROM course_content WHERE owner = {$_SESSION['user']} AND contenttype = 'exam'";
$exams = $db->execute($sql, "all");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PIE EDUCATION | Grades Management</title>
<link rel="stylesheet" type="text/css" href="/css/style-student.css" />
<link href="/css/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script type="text/javascript" src="/js/index.js"></script>
<script language="JavaScript" src="/js/ts_picker.js"></script>
<script language="Javascript1.2">
<!--
setTimeout('location.href="/logout.php?expire=1"',600000);
// -->
</script>
<script>
$(document).ready(function() {
	$("#accordion-grade").accordion({ autoHeight: false });
});

$(function() {
$( "#dialog-form" ).dialog({
	autoOpen: false,
	height: 500,
	width: 980,
	modal: true,
	closeOnEscape: true,
	buttons: {
		"Save The Grades": function() {
			//Aqui va el contenido del boton de Create an account
			alert("Boton presionado");
		},
		Cancel: function() {
			$( this ).dialog( "close" );
		}
	},
	close: function() {
		//Algo que hacer cuando se cierra la ventana
	}
});

$( ".openform" ).click(function() {
		alert(this.name);
		$( "#dialog-form" ).dialog( "open" );
	});
});
</script>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-35230372-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</head>

<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td bgcolor="#000000"><table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td width="350" height="30">&nbsp;</td>
        <td align="right" valign="bottom"><a href="class.php" class="top-menu" style="color:#999">MY CLASS</a> <a href="schedule.php" class="top-menu" style="color:#999">CALENDAR</a> <a href="homework.php" class="top-menu" style="color:#999">HOMEWORK</a> <a href="test.php" class="top-menu" style="color:#999">EXAMS</a> <a href="grades.php" class="top-menu" style="color:#999">GRADES</a> <a href="tools.php" class="top-menu" style="color:#999">TOOLS</a> <a href="/logout.php" class="top-menu" style="color:#999">SIGN OUT</a></td>
      </tr>
	  <tr>
        <td>&nbsp;</td>
        <td align="right" valign="bottom"><a href="/profile/" class="login-menu" style="color:#FFF"><?php echo $_SESSION['name'].' '.$_SESSION['lname']; ?></a> <a href="/common/redirect.php" class="login-menu" style="color:#FFF">My Documents</a> <a href="/network/" class="login-menu" style="color:#FFF">My Wall</a> <a href="/common/settings.php" class="login-menu" style="color:#FFF">Settings</a></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="30" style="background-image:url(/images/top-bg-student.png); background-repeat:repeat-x">&nbsp;</td>
  </tr>
  <tr>
    <td height="550" valign="top"><table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td><div id="fragment-4">
        <?php
		if($exams == false){
        echo '<table width="100%" border="0" cellspacing="4" cellpadding="4">
          <tr>
            <td align="center"><div style="font-family:Arial, Helvetica, sans-serif; font-size:18px; font-weight:bold; color:#F00">No exam to review was found</div><span style="font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#999">To create a new exam click on the <strong>"Create New Exam"</strong> tab above</span></td>
          </tr>
        </table>';
		} else {
			echo '<div id="accordion-grade">';
			foreach($exams as $exam_review){
				$sql = "SELECT * FROM exams WHERE exam_id = {$exam_review['id']} AND grade_provided = 'Yes'";
				$exam_review_results = $db->execute($sql, "all");
				echo '<h3><a href="#">'.$exam_review['title'].'</a></h3>
					<div>';
					if($exam_review_results == false){
				   echo '<table width="100%" border="0" align="center" cellpadding="4" cellspacing="4">
					  <tr>
						<td align="center"><div style="font-family:Arial, Helvetica, sans-serif; font-size:18px; font-weight:bold; color:#F00">No Answered Exams Has Been Found</div><span style="font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#999">We were unable to find any answered exam at this time, come back later</span></td>
					  </tr>
				   </table>';
					} else {
					echo '<table width="100%" border="0" align="center" cellpadding="4" cellspacing="4">
					  <tr>
						<td width="28%" align="center" bgcolor="#CCCCCC" style="font-family:Arial, Helvetica, sans-serif; font-size:14px"><strong>Full Name</strong></td>
						<td width="13%" align="center" bgcolor="#CCCCCC" style="font-family:Arial, Helvetica, sans-serif; font-size:14px"><strong>Correct</strong></td>
						<td width="13%" align="center" bgcolor="#CCCCCC" style="font-family:Arial, Helvetica, sans-serif; font-size:14px"><strong>Incorrect</strong></td>
						<td width="18%" align="center" bgcolor="#CCCCCC" style="font-family:Arial, Helvetica, sans-serif; font-size:14px"><strong>Total Questions</strong></td>
						<td width="13%" align="center" bgcolor="#CCCCCC" style="font-family:Arial, Helvetica, sans-serif; font-size:14px"><strong>Total Time</strong></td>
						<td width="14%" align="center" bgcolor="#CCCCCC" style="font-family:Arial, Helvetica, sans-serif; font-size:14px"><strong>Final Grade</strong></td>
					  </tr>';
					  $counter = 0;
					  foreach($exam_review_results as $review_data){
						if($counter % 2){
							$color = ' bgcolor="#ffffff"';
						} else {
							$color = "";
						}
						  echo '<tr'.$color.'>
							<td align="center" style="font-family:Arial, Helvetica, sans-serif; font-size:12px"><a href="#" style="color:#00F">'.$review_data['fname'].' '.$review_data['lname'].'</a></td>
							<td align="center" style="font-family:Arial, Helvetica, sans-serif; font-size:12px">'.$review_data['total_good'].'</td>
							<td align="center" style="font-family:Arial, Helvetica, sans-serif; font-size:12px">'.$review_data['total_bad'].'</td>
							<td align="center" style="font-family:Arial, Helvetica, sans-serif; font-size:12px">'.$review_data['total_questions'].'</td>
							<td align="center" style="font-family:Arial, Helvetica, sans-serif; font-size:12px">'.$review_data['time_taken'].' Seconds</td>
							<td align="center" style="font-family:Arial, Helvetica, sans-serif; font-size:12px">'.$review_data['total_result'].'</td>
						  </tr>';
						  $counter++;
					  }
					echo '</table>';
					}
				echo '</div>';
			}
		echo '</div>';	
		}
	?>
    </div></td>
      </tr>
    </table>
</td>
  </tr>
  <tr>
    <td height="30" align="center" style=" background-image:url(../images/bottom-bg-student.png); background-repeat:repeat-x;">&nbsp;</td>
  </tr>
  <tr>
    <td height="50" align="center" bgcolor="#000000" style="color:#fff; font-family:Arial, Helvetica, sans-serif">PIE.EDU All Rights Reserved 2012<br />
      <a href="/common/privacy.php" class="bottom-menu" style="color:#999">Privacy Policy</a> | <a href="/common/terms.php" class="bottom-menu"  style="color:#999">Terms of Use</a> | <a href="/help/main.php" class="bottom-menu" style="color:#999">Help Center</a> | <a href="/common/jobs.php" class="bottom-menu" style="color:#999">Jobs</a></td>
  </tr>
    </table>
<div id="dialog-form" title="Review The Exam">
    
</div>
</body>
</html>